package com.aqs.demo;

public class HelloWorld {
    static int apples = 0;
    static SingleHandlerLock singleHandlerLock=new SingleHandlerLock();
    public static void main(String[] args){
        Runnable runable = new Runnable() {
            @Override
            public void run() {
                for(int j = 0;j<100000;j++){
                    singleHandlerLock.lock();
                    apples++;
                    singleHandlerLock.unlock();
                }
                
            }
        };
        //work1
       Thread thread1= new Thread(runable);
       Thread thread2= new Thread(runable);
       thread1.start();
       thread2.start();
       try {
         thread1.join();
       } catch (InterruptedException e) {
         e.printStackTrace();
       }

       try {
        thread2.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      System.out.println("result is "+apples +"");
      
       System.out.println("main end");
    }
}